﻿using System.Collections.Generic;
using JetBrains.ReSharper.Psi.CSharp.Tree;
using Twins.Infrastructure;
using Twins.Interface;
using Twins.Interface.IProcesser;

namespace Twins.Classes.Hanlder
{
    public class ReceiveHashLineCodeFromProcesserCSharpStatement : IReceiveHashLineCodeFromProcesserCSharpStatement
    {
        public List<ILineCode> ReceiveHashLineCode(ICSharpStatement cSharpStatement, ICSharpStatement cSharpStatementBody, string textStatement)
        {
            var hashLineCodes = new List<ILineCode>();
            var hashLineCode = textStatement;
            var processerCSharpStatement = IoC.Resolve<IProcesser>("ProcesserCSharpStatement");
            var lineCodes = processerCSharpStatement.DoSomethingWith(cSharpStatementBody);
            if (lineCodes != null)
            {
                foreach (var lineCode in lineCodes)
                {
                    hashLineCode +=  lineCode.HashLineCode;
                    hashLineCodes.Add(lineCode);
                }
            }
            var hashLineCodesStatement = new List<ILineCode> { new LineCode(cSharpStatement, hashLineCode) };
            hashLineCodesStatement.AddRange(hashLineCodes);
            return hashLineCodesStatement;
        }
    }
}